// pages/my/index.js
Page({
  data: {
    userInfo: {
      id: '未分配',
      balance: '0.00',
      userName: '未登录',
      avatarUrl:  'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
    }
  },
  onLoad() {
    this.setData({
      userInfo: wx.getStorageSync('userInfo') ? JSON.parse(wx.getStorageSync('userInfo')) : this.data.userInfo
    })
  },
  getUserAvatar({ detail: { avatarUrl } }) {
    const userInfo = { ...this.data.userInfo}
    userInfo.avatarUrl = avatarUrl
    userInfo.id = Date.now()
    this.setData({
      userInfo
    })
    wx.setStorageSync('userInfo', JSON.stringify(userInfo))
    wx.utils.toast('头像信息已获取')
  },
  getUserName({ detail: { value } }) {
    const userInfo = { ...this.data.userInfo}
    userInfo.userName = value
    this.setData({
      userInfo: userInfo
    })
    wx.setStorageSync('userInfo', JSON.stringify(userInfo))
  }
})